package ifest.ontology;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class IFEST_Class_Mapping {
	//Class
	public String PROCESS_ACTIVITY="";
	public String DOMAIN_ACTIVITY="";
	public String METHOD_ACTIVITY="";
	public String ENGINEERING_DOMAIN="";
	public String VIEWPOINT="";
	 public String ARTIFACT="";
	 public String DOMAIN_ARTIFACT="";
	 public String METHOD_ARTIFACT="";
	 public String ARTIFACT_DEFINITION="";
	 public String DOMAIN_ARTIFACT_DEFINITION="";
	 public String METHOD_ARTIFACT_DEFINITION="";
	 public String TOOL="";
	 public String TOOLTYPE="";
	 public String MODELINGLANGUAGE="";
	 public String REPRESENTATIONLANGUAGE="";
	 //Reference
	 public String HAVE_VIEWPOINT="";
	 public String ENGINEERINGDOMAIN_PERFORMS="";
	 public String ENGINEERINGDOMAIN_RELIES="";
	 public String PROCESSACTIVITY_APPLIES="";
	 public String PROCESSACTIVITY_CONSUMS="";
	 public String PROCESSACTIVITY_PRODUCES="";
	 public String PROCESSACTIVITY_SPECIFIEDFROM="";
	 public String TOOL_CLASSIFIEDIN="";
	 public String TOOL_CONSTRAINTBY="";
	 public String TOOL_SUPPORT="";
	 public String TOOLTYPE_BELONGTO="";
	 public String TOOLTYPE_SUPPORTS="";
	 public String ARTIFACT_CONFORMS="";
	 public String ARTIFACTDEFINTITION_CATEGORIZED;
	 public String METHODARTIFACT_SPECIALIZED="";
	 //Attribute
	 public String HAVE_NAME_VALUE="";
	IFEST_Class_Mapping(String xmlFile) throws SAXException, IOException, ParserConfigurationException
	{
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	    DocumentBuilder docBuilder = factory.newDocumentBuilder();
	    Document doc = docBuilder.parse(new File(xmlFile));
	    doc.getDocumentElement().normalize();
	    Node root = doc.getDocumentElement();
	    Node node = doc.getElementsByTagName("class").item(0);
	    NodeList list = node.getChildNodes();
	    for( int i=0;i<list.getLength();i++)
	    {
	    	if(list.item(i).getNodeType()==Node.ELEMENT_NODE){
	    	Element e = (Element) list.item(i);
	    	String value = e.getAttribute("uri");
	    	if (e.getNodeName().equalsIgnoreCase("process_activity"))
	    	{
	    		PROCESS_ACTIVITY = value;
	    	}
	    	if (e.getNodeName().equalsIgnoreCase("domain_activity"))
	    	{
	    		DOMAIN_ACTIVITY = value;
	    	}
	    	if (e.getNodeName().equalsIgnoreCase("method_activity"))
	    	{
	    		METHOD_ACTIVITY = value;
	    	}
	    	if (e.getNodeName().equalsIgnoreCase("engineering_domain"))
	    	{
	    		ENGINEERING_DOMAIN = value;
	    	}
	    	if (e.getNodeName().equalsIgnoreCase("viewpoint"))
	    	{
	    		VIEWPOINT = value;
	    	}
	    	if (e.getNodeName().equalsIgnoreCase("tool"))
	    	{
	    		TOOL = value;
	    	}
	    	if (e.getNodeName().equalsIgnoreCase("tooltype"))
	    	{
	    		TOOLTYPE = value;
	    	}
	    	if (e.getNodeName().equalsIgnoreCase("artifact"))
	    	{
	    		ARTIFACT = value;
	    	}
	    	if (e.getNodeName().equalsIgnoreCase("method_artifact"))
	    	{
	    		METHOD_ARTIFACT = value;
	    	}
	    	if (e.getNodeName().equalsIgnoreCase("domain_artifact"))
	    	{
	    		DOMAIN_ARTIFACT = value;
	    	}
	    	if (e.getNodeName().equalsIgnoreCase("artifact_definition"))
	    	{
	    		ARTIFACT_DEFINITION = value;
	    	}
	    	if (e.getNodeName().equalsIgnoreCase("method_artifact_definition"))
	    	{
	    		METHOD_ARTIFACT_DEFINITION = value;
	    	}
	    	if (e.getNodeName().equalsIgnoreCase("domain_artifact_definition"))
	    	{
	    		DOMAIN_ARTIFACT_DEFINITION = value;
	    	}
	    	if (e.getNodeName().equalsIgnoreCase("modeling_language"))
	    	{
	    		MODELINGLANGUAGE = value;
	    	}
	    	if (e.getNodeName().equalsIgnoreCase("representation_language"))
	    	{
	    		REPRESENTATIONLANGUAGE = value;
	    	}
	    	}
	    }
	    node = doc.getElementsByTagName("objectProperties").item(0);
	    list = node.getChildNodes();
	    for( int i=0;i<list.getLength();i++)
	    {
	    	if(list.item(i).getNodeType()==Node.ELEMENT_NODE){
	    		Element e = (Element) list.item(i);
		    	String value = e.getAttribute("uri");
		    	if (e.getNodeName().equalsIgnoreCase("haveViewpoints"))
		    	{
		    		HAVE_VIEWPOINT = value;
		    	}
		    	if (e.getNodeName().equalsIgnoreCase("artifactDefinition_categorized"))
		    	{
		    		ARTIFACTDEFINTITION_CATEGORIZED = value;
		    	}
		    	if (e.getNodeName().equalsIgnoreCase("engineeringDomain_performs"))
		    	{
		    		ENGINEERINGDOMAIN_PERFORMS = value;
		    	}
		    	if (e.getNodeName().equalsIgnoreCase("engineeringDomain_relies"))
		    	{
		    		ENGINEERINGDOMAIN_RELIES = value;
		    	}
		    	if (e.getNodeName().equalsIgnoreCase("processActivity_applies"))
		    	{
		    		PROCESSACTIVITY_APPLIES = value;
		    	}
		    	if (e.getNodeName().equalsIgnoreCase("processActivity_consums"))
		    	{
		    		PROCESSACTIVITY_CONSUMS = value;
		    	}
		    	if (e.getNodeName().equalsIgnoreCase("processActivity_produces"))
		    	{
		    		PROCESSACTIVITY_PRODUCES = value;
		    	}
		    	if (e.getNodeName().equalsIgnoreCase("processActivity_specifiedFrom"))
		    	{
		    		PROCESSACTIVITY_SPECIFIEDFROM = value;
		    	}
		    	if (e.getNodeName().equalsIgnoreCase("tool_classifiedIn"))
		    	{
		    		TOOL_CLASSIFIEDIN = value;
		    	}
		    	if (e.getNodeName().equalsIgnoreCase("tool_constraintBy"))
		    	{
		    		TOOL_CONSTRAINTBY = value;
		    	}
		    	if (e.getNodeName().equalsIgnoreCase("tool_support"))
		    	{
		    		TOOL_SUPPORT = value;
		    	}
		    	if (e.getNodeName().equalsIgnoreCase("tooltype_belongTo"))
		    	{
		    		TOOLTYPE_BELONGTO = value;
		    	}
		    	if (e.getNodeName().equalsIgnoreCase("tooltype_supports"))
		    	{
		    		TOOLTYPE_SUPPORTS = value;
		    	}
		    	if (e.getNodeName().equalsIgnoreCase("artifact_conforms"))
		    	{
		    		ARTIFACT_CONFORMS = value;
		    	}
		    	if (e.getNodeName().equalsIgnoreCase("methodArtifact_specialized"))
		    	{
		    		METHODARTIFACT_SPECIALIZED = value;
		    	}
	    	}
	    	
	    }
	    node = doc.getElementsByTagName("dataProperties").item(0);
	    list = node.getChildNodes();
	    for( int i=0;i<list.getLength();i++)
	    {
	    	if(list.item(i).getNodeType()==Node.ELEMENT_NODE)
	    	{
	    		Element e = (Element) list.item(i);
		    	String value = e.getAttribute("uri");
		    	if (e.getNodeName().equalsIgnoreCase("name"))
		    	{
		    		HAVE_NAME_VALUE = value;
		    	}
	    	}
	    	
	    }
	}
}
